import React, {Component} from 'react';

class TestCrossDomain extends Component {
    handClick(event) {
        var xhr = new XMLHttpRequest();
        //测试springboot跨域
        //xhr.open('GET', "http://localhost:8080/crossdomain/hello", true);
        //测试react proxy
        //xhr.open('GET', "http://localhost:3000/crossdomain/hello", true);
        //测试nginx反向代理
        xhr.open('GET', "http://localhost/crossdomain/hello", true);
        xhr.send();
        xhr.onload = function (e) {
            var text = xhr.responseText;
            if (xhr.status === 200) {
                console.info(text);
            } else {
                var error = new Error(text);
                error.response = xhr;
                console.info(error);
            }
        };
    }

    render() {
        return (
            <button onClick={this.handClick}>TestCrossDomain</button>
        );
    }
}

export default TestCrossDomain;

